package acwing._2LanQiao._9DP;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._9DP
 * @File : Q1078.java
 * @Author : WangRuoyu
 * @Date : 2023/3/25 10:05
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Q1078 { // 求树的直径
    static final int N = 200010;
    static final int M = 2 * N;
    static int n;
    static int idx = 0;
    static int[] h;
    static int[] e = new int[M];
    static int[] ne = new int[M];
    static int[] d1 = new int[N];
    static int[] d2 = new int[N];
    static int[] up = new int[N];
    static int[] p1 = new int[N];
    static int maxlen = -1;

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static void dfs_d(int u, int father) {
        for (int i = h[u]; i != -1; i = ne[i]) {
            int j = e[i];
            if (j != father) {
                dfs_d(j, u);
                int distance = d1[j] + 1;
                if (distance > d1[u]) {
                    d2[u] = d1[u];
                    d1[u] = distance;
                    p1[u] = j;
                } else if (distance > d2[u]) {
                    d2[u] = distance;
                }
            }
        }
        maxlen = Math.max(d1[u] + d2[u], maxlen);
    }

    static void dfs_u(int u, int father) {
        for (int i = h[u]; i != -1; i = ne[i]) {
            int j = e[i];
            if (j != father) {
                up[j] = up[u] + 1;
                if (p1[u] == j) up[j] = Math.max(up[j], d2[u] + 1);
                else up[j] = Math.max(up[j], d1[u] + 1);
                dfs_u(j, u);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");

        n = Integer.parseInt(words[0]);
        h = new int[n];
        Arrays.fill(h, -1);

        for (int i = 0; i < n - 1; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            add(a, b);
            add(b, a);
        }

        dfs_d(0, -1);
        dfs_u(0, -1);

        for (int i = 0; i < n; ++i) {
            if (d1[i] + Math.max(d2[i], up[i]) == maxlen) System.out.println(i);
        }
    }
}

